<?php
/**
 * Edit comment feed procedure
 *
 * @author University of London Computer Centre
 * @version 1.1.0
 * @package ArchivePress
 * @subpackage pages
 * @global ArchivePress $ArchivePress
 */

// globals
global $ArchivePress;

// actions URL
$responder = get_bloginfo( 'wpurl' ).'/wp-admin/admin.php?page=archivepress/pages/responder.php';

// FEED ID
$feed_id = "";
if(isset($_GET["feed_id"])){
    $feed_id = (int)attribute_escape($_GET["feed_id"]);
}


// GET FEED
$feed = $ArchivePress->getFeed($feed_id);
// feed not found
if($feed === null) {
    echo '<div class="wrap">
            <div class="icon32" id="icon-archivepress"><br /></div>
            <h2>'.__("Edit Comment Feed", ARCHIVEPRESS).'
                <a class="button add-new-h2" href="admin.php?page=archivepress/pages/edit-comments.php" title="'.__("Back to Comment Feeds", ARCHIVEPRESS).'" >'.__("Back to the Comment Feed Page", ARCHIVEPRESS).'</a>
            </h2>
            <div class="updated fade below-h2" id="message">
                <p>
                    '.__("No Feed Found!", ARCHIVEPRESS).'<br />
                </p>
            </div>
         </div>';
} else {
    // Feed found

    // CHECK FOR MESSAGES
    $message = "";
    // update
    if(array_key_exists("update", $_GET)){
        $message = __("Settings updated", ARCHIVEPRESS);
    }


    if($message != ""){
        $message = '<div class="updated fade below-h2" id="message">
                        <p>
                            '.$message.'<br />
                        </p>
                    </div>';
    }

    echo '<div class="wrap">
            <div class="icon32" id="icon-archivepress"><br /></div>
            <h2>'.__("Edit Comment Feed", ARCHIVEPRESS).'
                <a class="button add-new-h2" href="admin.php?page=archivepress/pages/edit-comments.php" title="'.__("Back to Comment Feeds", ARCHIVEPRESS).'" >'.__("Back to the Comment Feed Page", ARCHIVEPRESS).'</a>
            </h2>
            '.$message.'
            <form method="post" action="admin.php?page=archivepress/pages/edit-comment.php">
                <input type="hidden" name="back" value="edit-comment" />
                <input type="hidden" name="feed_id" value="'.$feed_id.'" />
                <input type="hidden" name="' . WP_ARCHIVEPRESS_PREFIX . 'action" value="editcomment" />';

    // security
    wp_nonce_field(WP_ARCHIVEPRESS_PREFIX . 'edit-comment_feed_' . $feed["id"]);

    // Feed Settings
    echo'
                <table class="form-table">
                    <tr valign="top">
                        <th scope="row">'.__("Feed Name").'</th>
                        <td>
                            <b>'.$ArchivePress->cleanOutput($feed["name"]).'"</b>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><label for="' . WP_ARCHIVEPRESS_PREFIX . 'feedlink">'.__("Active Link").'</label></th>
                        <td>
                            <select  name="' . WP_ARCHIVEPRESS_PREFIX . 'feedlink" id="' . WP_ARCHIVEPRESS_PREFIX . 'feedlink">';
                            // get links
                            $links = $ArchivePress->getLinksForFeed($feed_id);
                            foreach($links as $link) {
                                echo '
                                <option value="'.$link["id"].'"'; if($link["is_the_one_in_use"] == "yes") echo 'selected="selected"'; echo' >'.$ArchivePress->cleanOutput($link["url"]).'</option>
                                ';
                            }
    echo'
                            </select>
                            <span class="description">'.__("Each Blog can have more than one Feed (RSS, Atom, ...), so you can decide which one use.", ARCHIVEPRESS).'</span> <br /><span class="description arpr_alert">'.__("Change the active link could duplicate posts.", ARCHIVEPRESS).'</span>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row">'.__("Activate Feed").'</th>
                        <td>
                            <fieldset>
                                <legend class="screen-reader-text">
                                    <span>'.__("Activate Feed").'</span>
                                </legend>
                                <label for="' . WP_ARCHIVEPRESS_PREFIX . 'feedactive">
                                    <input name="' . WP_ARCHIVEPRESS_PREFIX . 'feedactive" type="checkbox" id="' . WP_ARCHIVEPRESS_PREFIX . 'feedactive" value="yes" '; if($feed["active"] == "yes") echo 'checked="checked"'; echo' />
                                    '.__("check to make it active").'<br />
                                    <span class="description arpr_alert">'.__("If the Post Feed is Inactive, this feed WON'T be fetched also if the field is checked.", ARCHIVEPRESS).'</span>
                                </label>

                            </fieldset>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><label for="' . WP_ARCHIVEPRESS_PREFIX . 'feedinterval">'.__("Fetch Interval").'</label></th>
                        <td>
                            <select  name="' . WP_ARCHIVEPRESS_PREFIX . 'feedinterval" id="' . WP_ARCHIVEPRESS_PREFIX . 'feedinterval">';
                            // get intervals
                            $intervals = array(
                                                    ArchivePressOptions::FETCH_INTERVAL_HOURLY  => __("Every Hour", ARCHIVEPRESS),
                                                    ArchivePressOptions::FETCH_INTERVAL_FOURTAD => __("Four Times a Day", ARCHIVEPRESS),
                                                    ArchivePressOptions::FETCH_INTERVAL_TID     => __("Three Times a Day", ARCHIVEPRESS),
                                                    ArchivePressOptions::FETCH_INTERVAL_BID     => __("Two Times a Day", ARCHIVEPRESS),
                                                    ArchivePressOptions::FETCH_INTERVAL_DAILY   => __("Every Day", ARCHIVEPRESS)
                                               );

                            foreach($intervals as $value => $text) {
                                echo '
                                <option value="'.$value.'"'; if($value == $feed["interval"]) echo 'selected="selected"'; echo' >'.$ArchivePress->cleanOutput($text).'</option>
                                ';
                            }
    echo'
                            </select>
                            <span class="description">'.__("How often the Feed has to be fetched.", ARCHIVEPRESS).'</span> <br /><span class="description arpr_tip">'.__("Too often generate more trafic on your blog, but too infrequently could let your server use too many resources.", ARCHIVEPRESS).'</span>
                        </td>
                    </tr>

                </table>

                <p class="submit">
                <input type="submit" class="button-primary" value="'.__('Save Changes', ARCHIVEPRESS).'" />
                </p>';

    echo '
            </form>
         </div>';
}


?>